<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>订单表</title>
    <!--引入vue.js库-->
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> -->
    <script src="/js/vue.js"></script>
    <!-- element-ui引入样式 展示数据的 -->
    <!--<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">-->
    <link rel="stylesheet" href="/css/index.css">
    <!-- element-ui引入组件库 -->
    <!--<script src="https://unpkg.com/element-ui/lib/index.js"></script>-->
    <script src="/js/index.js"></script>
    <!--引入axios库  从后端获取数据-->
    <!--<script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
    <script src="/js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <!--搜索-->
    <el-row>
        <!--一行24列-->
        <!-- v-model 实现表单元素和数据的双向绑定-->
        <el-col :span="3">
            <el-input v-model="searchForm.orderid" size="mini" placeholder="请输入订单id"></el-input>
        </el-col>
        <el-col :span="3">
            <el-input v-model="searchForm.scenicid" size="mini" placeholder="请输入景区Id"></el-input>
        </el-col>
        <el-col :span="2">
            &nbsp; &nbsp; &nbsp;<el-button type="success" icon="el-icon-search" size="mini" @click="search">搜索</el-button>&nbsp;
        </el-col>
        <el-col :span="2">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">添加</el-button>&nbsp;
        </el-col>
        <el-col :span="14"></el-col>
    </el-row><br>

    <!--table 数据-->
    <el-table
            :data="tableData"
            border
            style="width: 100%">
        <!-- v-bind命令绑定属性 简写为':(冒号)'-->
<!--        <el-table-column-->
<!--                align="center"-->
<!--                fixed-->
<!--                prop="orderid"-->
<!--                label="订单id"-->
<!--                width="120">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--                prop="scenicid"-->
<!--                label="景区id"-->
<!--                width="120">-->
<!--        </el-table-column>-->
        <el-table-column
                prop="orderno"
                label="订单号"
                width="120">
        </el-table-column>
        <el-table-column
                prop="ywrq"
                label="游玩日期"
                width="120">
        </el-table-column>
        <el-table-column
                prop="zczfsj"
                label="最迟取票日期"
                width="120">
        </el-table-column>
        <el-table-column
                prop="zcqprq"
                label="最迟取票日期"
                width="120">
        </el-table-column>
        <el-table-column
                prop="ptype"
                label="支付方式"
                width="120">
        </el-table-column>
<!--        <el-table-column-->
<!--                prop="ticketid"-->
<!--                label="门票id"-->
<!--                width="120">-->
<!--        </el-table-column>-->
        <el-table-column
                prop="scenicname"
                label="景区名称"
                width="120">
        </el-table-column>
        <el-table-column
                prop="ticketname"
                label="门票名称"
                width="120">
        </el-table-column>
        <el-table-column
                align="center"
                fixed
                prop="zcdpsj"
                label="最迟订票时间"
                width="120">
        </el-table-column>
        <el-table-column
                prop="price"
                label="单价"
                width="120">
        </el-table-column>
        <el-table-column
                prop="tcount"
                label="总票数"
                width="120">
        </el-table-column>
        <el-table-column
                prop="tprice"
                label="总票价"
                width="120">
        </el-table-column>
        <el-table-column
                prop="qprname"
                label="取票人名字"
                width="120">
        </el-table-column>
        <el-table-column
                prop="qprsj"
                label="取票人时间"
                width="120">
        </el-table-column>
<!--        <el-table-column-->
<!--                prop="userid"-->
<!--                label="用户id"-->
<!--                width="120">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--                prop="codeid"-->
<!--                label="状态码表id"-->
<!--                width="120">-->
<!--        </el-table-column>-->
<!--        <el-table-column-->
<!--                prop="state"-->
<!--                label="状态"-->
<!--                width="120">-->
<!--        </el-table-column>-->
        <el-table-column
                prop="ordertime"
                label="下单时间"
                width="120">
        </el-table-column>

        <el-table-column label="操作" width="160" align="center" fixed="right" >
            <!--fixed="right"-->
            <template slot-scope="scope">
                <el-button
                        size="small"
                        type="primary"
                        @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button
                        size="small"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>


    <!--分页功能-->
    <!-- v-on命令绑定事件 简写为'@(at符号)'-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[2,5,10,15,20]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>


    <!--添加或者更新的form表单-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
<!--            <el-form-item label="景区id" :label-width="formLabelWidth">-->
<!--                <el-input v-model="form.scenicid" autocomplete="off"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="订单号" :label-width="formLabelWidth">-->
<!--                <el-input v-model="form.orderno" autocomplete="off"></el-input>-->
<!--            </el-form-item>-->
            <el-form-item label="游玩日期" :label-width="formLabelWidth">
                <el-input v-model="form.ywrq" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="最迟取票日期" :label-width="formLabelWidth">
                <el-input v-model="form.zczfsj" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="最迟取票日期" :label-width="formLabelWidth">
                <el-input v-model="form.zcqprq" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="支付方式" :label-width="formLabelWidth">
                <el-input v-model="form.ptype" autocomplete="off"></el-input>
            </el-form-item>
<!--            <el-form-item label="门票id" :label-width="formLabelWidth">-->
<!--                <el-input v-model="form.ticketid" autocomplete="off"></el-input>-->
<!--            </el-form-item>-->
            <el-form-item label="景区名称" :label-width="formLabelWidth">
                <el-input v-model="form.scenicname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="门票名称" :label-width="formLabelWidth">
                <el-input v-model="form.ticketname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="最迟订票时间" :label-width="formLabelWidth">
                <el-input v-model="form.zcdpsj" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="单价" :label-width="formLabelWidth">
                <el-input v-model="form.price" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="总票数" :label-width="formLabelWidth">
                <el-input v-model="form.tcount" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="总票价" :label-width="formLabelWidth">
                <el-input v-model="form.tprice" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="取票人名字" :label-width="formLabelWidth">
                <el-input v-model="form.qprname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="取票人时间" :label-width="formLabelWidth">
                <el-input v-model="form.qprsj" autocomplete="off"></el-input>
            </el-form-item>
<!--            <el-form-item label="用户id" :label-width="formLabelWidth">-->
<!--                <el-input v-model="form.userid" autocomplete="off"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="状态码表id" :label-width="formLabelWidth">-->
<!--                <el-input v-model="form.codeid" autocomplete="off"></el-input>-->
<!--            </el-form-item>-->
<!--            <el-form-item label="状态" :label-width="formLabelWidth">-->
<!--                <el-input v-model="form.state" autocomplete="off"></el-input>-->
<!--            </el-form-item>-->
            <el-form-item label="下单时间" :label-width="formLabelWidth">
                <el-input v-model="form.ordertime" autocomplete="off"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addOrUpdate">确 定</el-button>
        </div>
    </el-dialog>

</div>


<script>
    var vue = new Vue({
        el:"#app",
        data(){//存放使用的所有属性数据
            return{
                tableData:[], //表格数据
                currentPage:1, //页码 第几页
                pageSize:5, //每页显示数量(设置默认值,必须对应page-sizes里面的一个数)
                total:100, //分页总数量
                searchForm:{orderid:'',scenicid:''},//封装查询对象
                dialogFormVisible: false, //是否显示对话框
                title:'订单添加', //默认显示title
                form:{orderid:'',scenicid:'',orderno:'',ywrq:'',zczfsj:'',zcqprq:'',
                    ptype:'',ticketid:'',scenicname:'',ticketname:'',zcdpsj:'',price:''
                    ,tcount:'',tprice:'',qprname:'',qprsj:'',userid:'',codeid:''
                    ,state:'',ordertime:''}, //form表单
                formLabelWidth:'120px', //label宽度
            }
        },
        created:function(){
            //调用加载数据方法
            this.loadData();
        },
        methods:{
            //封装请求数据的方法
            loadData(){
                //在使用axios发生请求之前，定义变量_this=this，代指Vue对象
                var _this = this;
                //使用axios向后台发请求
                axios.post('/sbsnorder/queryByPage', //请求的url
                    {"pageNo":_this.currentPage,"pageSize":_this.pageSize,
                        "data":{"orderid":_this.searchForm.orderid,
                            "scenicid":_this.searchForm.scenicid}}) //请求参数 json格式
                    .then(function (response) { //回调函数
                        //前端控制台打印   response  是json对象
                        console.log(response);
                        //JSON.stringify() 把json对象转为字符串
                        console.log(JSON.stringify(response));
                        //response获取后台数据时，一定要加data response.data相当于从响应的body中获取
                        if(response.data.code==200){
                            //这里面直接写this相当于axios对象，不是vue对象
                            /*this.tableData = response.data.data.list; 错误的*/
                            _this.tableData = response.data.data.list; //正确的
                            _this.total = response.data.data.total;
                        }

                    })
                    .catch(function (error) { //异常处理
                        console.log(error);
                    });
            },

            //每页数量发生变化
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize = val;
                //调用加载数据方法
                this.loadData();
            },
            //页码(第几页)发生变化
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.currentPage = val;
                //调用加载数据方法
                this.loadData();
            },



            //搜索方法
            search(){
                this.loadData();
            },

            //跳转更新
            handleEdit(index, row) { //index 当前行的行标-从0开始，row 当前行的数据
                console.log(index, row);
                //alert(index+","+JSON.stringify(row));
                //row = {"deptName":'xxx',"loc":'xxx',deptNo:xxx}
                this.dialogFormVisible = true;
                //让title值也发生变化
                this.title='订单更新';
                //给表单赋值  双向绑定，执行更新操作时，把deptNo参数也传到后端
                this.form = row;
            },

            //跳转添加
            handleAdd(){
                //让对话框显示
                this.dialogFormVisible = true;
                //让title值也发生变化
                this.title='订单添加';
                //让form清空
                this.form={};
            },

            //真正的添加或更新
            addOrUpdate(){
                //定义请求路径，默认添加
                var uri = "/sbsnorder/add";
                //判断是否是更新
                if (this.title=='订单更新'){
                    uri = "/sbsnorder/update"
                }
                //在使用axios发生请求之前，定义变量_this=this，代指Vue对象
                var _this = this;
                //使用axios向后台发请求
                axios.post(uri, //请求的url
                    this.form) //请求参数 json格式    因为this.form = row;  此时deptNo参数也传到后端
                    .then(function (response) {//回调函数
                        //前端控制台打印   response 是json对象
                        console.log(response);
                        // JSON.stringify() 把json对象转为字符串
                        console.log(JSON.stringify(response));
                        //response获取后台数据时，一定要加data response.data相当于从响应的body中获取
                        if (response.data.code==200){
                            //提示成功
                            _this.$message({
                                message: '恭喜你，这是一条成功消息',
                                type: 'success'
                            });
                            //关闭弹框
                            _this.dialogFormVisible = false;
                            //重新加载数据
                            _this.loadData();
                        }else {
                            this.$message.error('错了哦，这是一条错误消息');
                        }
                    })
                    .catch(function (error) {//异常处理
                        console.log(error);
                    });
            },


            //处理删除
            handleDelete(index, row) {
                console.log(index, row);
                //alert(index+","+JSON.stringify(row));
                console.log(row.orderid);
                var id = row.orderid;
                this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //定义请求路径，默认添加
                    var uri = "/sbsnorder/deleteById?orderid="+id;
                    console.log("id:"+id);
                    //在使用axios发生请求之前，定义变量_this=this，代指Vue对象
                    var _this = this;
                    //使用axios向后台发请求
                    axios.delete(uri //请求的url
                    ) //请求参数 json格式    因为this.form = row;  此时deptNo参数也传到后端
                        .then(function (response) {//回调函数
                            //前端控制台打印   response 是json对象
                            console.log(response);
                            // JSON.stringify() 把json对象转为字符串
                            console.log(JSON.stringify(response));
                            //response获取后台数据时，一定要加data response.data相当于从响应的body中获取
                            if (response.data.code==200){
                                //提示成功
                                _this.$message({
                                    message: '恭喜你，删除成功',
                                    type: 'success'
                                });
                                //重新加载数据
                                _this.loadData();
                            }else {
                                this.$message.error('对不起，删除失败');
                            }
                        })
                        .catch(function (error) {//异常处理
                            console.log(error);
                        });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    })
</script>
</body>
</html>